<template>
	<!-- components/public_pay/public_pay.wxml -->

	<view class="payPopContainer" v-if="!globalData.iOSMiniPay_forbid" v-show="!timeoutpay">
		<!-- 遮罩 -->
		<view :class="'payPopMask ' + (showPayPop ? 'showPop' : '')" @touchmove.stop.prevent="trueFun"></view>
		<view class="loading" v-if="payLoading"> <image :src="`${imgStaticPath}/loading.png?v=${imgVersion}`" mode="aspectFill"></image></view>
		<!-- 弹窗 支付 -->
		<view :class="'payPop payPhonePop ' + (showPayPop ? 'showPop' : '')">
			<view class="payInfoShow">
				<!-- 支付标题 -->
				<view class="pi-title">{{ payInfo.subject }}需支付</view>
				<view class="h2" @tap="showtoast">
					<text class="span" v-if="currency">{{ currency.symbol }}</text>
					<text class="b" id="amout">{{ payInfo.order_amount || '0.00' }}</text>
				</view>
				<view class="p" v-if="needPayTime">
					支付时间:
					<text class="payCutDown span">
						<text class="em">{{ timeInfo.hh }}</text>
						:
						<text class="em">{{ timeInfo.mm }}</text>
						:
						<text class="em">{{ timeInfo.ss }}</text>
					</text>
				</view>
			</view>
			<view class="payListBox">
				<view class="close_pay_pop" @tap="cancelConfirm">
					<image mode="aspectFit" :src="imgPath + '/payPop/close.png?v=' + imgVersion"></image>
				</view>
				<view class="ul">
					<view :class="
                            'check-item li ' +
                            (onChosePay == 'balance' && payInfo.order_amount <= money ? 'paychosed' : '') +
                            ' ' +
                            (payInfo.order_amount > money ? 'disabled_pay' : '')
                        " id="balance" data-code="balance" @tap="changePay"
						:data-click="payInfo.order_amount > money ? 0 : 1" v-if="userid && !filterPay">
						<view class="left_item div">
							<view class="check-item-img">
								<image class="img" mode="aspectFit"
									:src="imgPath + '/payPop/balance.png?v=' + imgVersion" />
							</view>
							<view class="check-item-txt">
								<view class="h3">
									余额
									<text
										v-if="payInfo.order_amount <= money">(可用余额{{ currency.symbol }}{{ money }})</text>
									<text v-else>(余额不足，可用余额{{ currency.symbol }}{{ money }})</text>
								</view>
							</view>
						</view>
						<view class="check-item-right">
							<!-- <input type="radio" name="paytype" value="balance" /> -->
							<view class="checkbox-icon-round span">
								<image mode="aspectFiill" :src="imgPath + '/payPop/chosed.png?v=' + imgVersion" />
							</view>
						</view>
						<view class="investMoney" v-if="payInfo.order_amount > money"
							data-href="/deposit.html?paytype=deposit" @tap="goLink">充值</view>
					</view>
					<block v-for="(item, index) in payment" :key="index">
						<view v-if="item.pay_code != 'huoniao_bonus' || !filterPay" :class=" 'check-item li ' + (item.pay_code == onChosePay? 'paychosed' : '') + '  ' + (payInfo.order_amount > bouns && item.pay_code == 'huoniao_bonus' ? 'disabled_pay' : '') " :data-code="item.pay_code" :data-click="payInfo.order_amount > bouns && item.pay_code == 'huoniao_bonus' ? 0 : 1" @tap="changePay">
							<view class="left_item div">
								<view class="check-item-img">
									<image v-if="item.pay_code == 'huoniao_bonus'" class="img" mode="aspectFit"
										:src="imgPath + '/payPop/bonus_pay.png?v=' + imgVersion" />
									<image v-else class="img" mode="aspectFit" :src="item.pay_icon" />
								</view>
								<view class="check-item-txt">
									<view class="h3" v-if="item.pay_code == 'huoniao_bonus'">
										{{ item.pay_name }}
										<text
											v-if="payInfo.order_amount <= bouns">(可用余额{{ currency.symbol }}{{ bouns }})</text>
										<text v-else>(余额不足，可用余额{{ currency.symbol }}{{ bouns }})</text>
									</view>
									<view class="h3" v-else>{{ item.pay_name }}</view>
								</view>
							</view>
							<view class="investMoney" @tap="goLink"
								v-if="payInfo.order_amount > bouns && item.pay_code == 'huoniao_bonus'"
								data-href="/recharge.html">充值</view>
							<view class="check-item-right" v-else>
								<!-- <input type="radio" name="paytype" value="{{item.pay_code}}" /> -->
								<view class="checkbox-icon-round span">
									<image mode="aspectFiill" :src="imgPath + '/payPop/chosed.png?v=' + imgVersion" />
								</view>
							</view>
						</view>
					</block>
				</view>
			</view>
			<view class="btn_pay a" @tap="toPay"><text style="display: block" class="span">立即付款</text></view>

			<!-- 取消支付 确认弹窗 -->
			<view :class="'payCancelMask ' + (showCancelPop ? 'showPop' : '')"></view>
			<view :class="'payCancelPop ' + (showCancelPop ? 'showPop' : '')" :style="!needPayTime?'height:250rpx;':''">
				<!-- <view class="payCancelPop" hidden="{{!showCancelPop}}"> -->
				<view class="h4">确定放弃本次付款？</view>
				<view class="p" v-if="needPayTime">
					您的订单在
					<text class="daojs_order span">{{ timeInfo.showText }}</text>
					内未支付将被取消， 请尽快完成支付
				</view>
				<view class="payBtns">
					<view class="cancelPay a" @tap="cancelPay">放弃</view>
					<view class="keepPay a" @tap="keepPay">继续支付</view>
				</view>
			</view>
		</view>

		<!-- 支付密码 -->
		<view class="inputBox">
			<input type="number" :hold-keyboard="true" :focus="hasshowPwdPop && focus" class="keyInp"
				@keyboardheightchange="showKeyboard" @input="inputPwd" maxlength="6" v-model="paypwdStr" />
		</view>
		<view :class="'payPwdPop ' + (showPwdPop ? 'showPop' : '')">
			<view class="payBackBtn a" @tap="hidePwdPop">
				<image :src="imgPath + '/payPop/arr_back.png?v=' + imgVersion" mode="aspectFit"></image>
			</view>
			<view class="h4">{{userInfo.paypwdCheck == 1 ? '输入' : '设置'}}支付密码</view>
			<view class="payPwdBox" :style="'padding-bottom:' + (keyboardHeight + 10) + 'px;'">
				<view class="p">请{{userInfo.paypwdCheck == 1 ? '输入' : '设置'}}6位数字密码确认支付</view>
				<view class="payPwdInp">
					<view class="ul" @tap="focusin">
						<view class="li" v-for="(item, i) in 6" :key="i">
							<text class="em" v-if="paypwd[i] || paypwd[i] == 0">•</text>
						</view>
					</view>
				</view>
				<view class="fpwtbox" v-if="userInfo.paypwdCheck == 1">
					<view data-href="/security-paypwdEdit.html?step=2" class="fpwt a" @tap="goLink">忘记密码?</view>
				</view>
				<view class="spwtbox" v-else>
					<view class="p">·避免使用连续或重复数字，类似“123456”“112233”</view>
					<view class="p">·避免使用手机号、证件号中的连续数字</view>
				</view>
				<view class="setPwdUp" v-if="userInfo.paypwdCheck != 1" @click="setPayPwd">确认并支付</view>
			</view>

			<!-- :style="`transform: translateY(${passwordConb?0:'100%'});`" -->
			<view :class="{'keyboard':true,'showKeyBoard':keyboardShow}" v-if="uniPlatform == 'web'">
				<view>
					<text @click="keyBoardIn(1)">1</text>
					<text @click="keyBoardIn(2)">2</text>
					<text @click="keyBoardIn(3)">3</text>
					<text @click="keyBoardIn(4)">4</text>
					<text @click="keyBoardIn(5)">5</text>
					<text @click="keyBoardIn(6)">6</text>
					<text @click="keyBoardIn(7)">7</text>
					<text @click="keyBoardIn(8)">8</text>
					<text @click="keyBoardIn(9)">9</text>
					<text class="none"></text>
					<text @click="keyBoardIn(0)">0</text>
					<text class="backSpace" :style="`background: url(${imgstatic}del_num.png) no-repeat 50%/60rpx;`"
						@click="paypwd = paypwd.slice(0,-1)"></text>
				</view>
			</view>
		</view>

		<view style="position: relative; z-index: 9999999999">
			<toast id="toast" ref="toasts"></toast>
		</view>
	</view>
</template>

<script>
	import toast from '../toast/toast';
	// components/public_pay/public_pay.js
	const app = getApp();
	// let _this;
	export default {
		components: {
			toast
		},
		data() {
			return {
				uniPlatform:'',
				imgstatic: `${app.globalData.masterDomain}/static/images/miniprograme/payPop/`,
				//图片版本号
				imgVersion: app.globalData.imgVersion,
				payLoading:false, // 请求loading
				imgStaticPath: app.globalData.imgStaticPath,
				imgPath: app.globalData.imgPath,
				globalData:app.globalData,
				//图片路径 小程序

				paypwd: [],

				//支付密码
				paypwdStr: '',

				//支付密码
				payment: [],

				//支付方式
				onChosePay: 'balance',

				money: 0,

				//余额
				bouns: 0,

				//购物卡余额,
				showPwdPop: false,

				//支付密码弹窗显示
				showCancelPop: false,

				//取消支付弹窗显示
				timeInfo: {
					dd: 0,
					hh: 0,
					ss: 0,
					mm: 0,
					showText: '0'
				},

				focus: true,
				hasshowPwdPop: false,
				checkIn: false,

				interVal: null,
				payInterval: null,
				keyboardHeight: 0,
				i: '',
				currency: {
					code: 'RMB',
					name: '人民币',
					rate: '1',
					short: '元',
					symbol: '￥'
				},
				timeoutpay: true,
				userid: app.globalData.userid,
				keyboardShow:false, //显示数字键盘
				userInfo:'',
			};
		},
		/**
		 * 组件的属性列表
		 */
		props: {
			filterPay:{ // 是否过滤支付方式  只显示第三方支付
				type: Boolean,
				default: false
			},
			showPayPop: {
				//支付弹窗显示
				type: Boolean,
				default: false
			},
			action: {
				type: String,
				default: 'payPhone'
			},
			service: {
				type: String,
				default: 'siteConfig'
			},
			payInfo: {
				//支付密码弹窗显示
				type: Object,
				default: {
					order_amount: '',
					order_sn: '',
					ordernum: '',
					service: '',
					timeout: 0
				}
			},
			// 电话类型
			callType: {
				type: Number,
				default: 0
			},
			// 是否需要显示倒计时
			needPayTime: {
				type: Boolean,
				default: true
			},
			// 是否需要支付成功的弹窗
			needSuccess: {
				type: Boolean,
				default: true
			},
			// showCancelPop:{  //取消支付弹窗显示
			//   type:Boolean,
			//   value:false,
			// },

			
		},
		emits:['paypopb','keepToCall'],
		/**
		 * 组件的方法列表
		 */
		methods: {
			ready: function() {
				const _this = this
				var interVals = setInterval(function() {
					if (app.globalData.appConfig && app.globalData.appConfig.currency) {
						_this.currency = app.globalData.appConfig.currency
						clearInterval(interVals);
					}
				}, 1000);

				
			},

			inputCodeFn(){},

			// 获取所有支付方式
			getPayment() {
				const _this = this
				var dataPrarm = 'service=siteConfig&action=payment';
				var urlData = app.encodeUrl(dataPrarm);
				_this.$ajax.get({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					if (data.state == 100) {
						// 平台切换
						let platForm = app.globalData.platForm;
						if (platForm == 'mp-weixin') {
							for (let i = 0; i < data.info.length; i++) {
								let item = data.info[i];
								if (item.pay_code == 'alipay' || (!_this.userid && item.pay_code ==
									'huoniao_bonus')) { //除掉微信支付
									data.info.splice(i, 1);
								}
							}
						} else if (platForm == 'mp-toutiao') {
							for (let i = 0; i < data.info.length; i++) {
								let item = data.info[i];
								if (item.pay_code == 'alipay' || item.pay_code == 'wxpay' || !_this.userid && item
									.pay_code ==
									'huoniao_bonus'
								) { //除掉微信和支付宝支付
									data.info.splice(i, 1);
								}
							}
						} else if (platForm == 'web') {
							if (!_this.userid || _this.filterPay) {
								for (let i = 0; i < data.info.length; i++) {
									let item = data.info[i];
									if (item.pay_code ==
										'huoniao_bonus') { //除掉微信支付
										data.info.splice(i, 1);
									}
								}
							}
						}
						if (!app.globalData.userid || _this.filterPay) {
							_this.onChosePay = data.info[0].pay_code
						}
						_this.payment = data.info;
					}
				})
			},

			// 获取用户当前信息
			getMemberInfo: function() {
				const _this = this
				var dataPrarm = 'service=member&action=detail&id=' + app.globalData.userid;
				var urlData = app.encodeUrl(dataPrarm);
				_this.$ajax.get({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					if (res.data.state == 100) {
						app.globalData.userInfo = res.data.info;
						_this.money = res.data.info.money * 1;
						//余额
						_this.bouns = res.data.info.bonus * 1 //购物卡余额
					}
				})
			},

			// 改变支付方式
			changePay(e) {
				const _this = this
				var pay = e.currentTarget.dataset.code;
				var click = e.currentTarget.dataset.click;
				// console.log(_this.payInfo);
				if (click != 0) {
					_this.onChosePay = pay;
				}
			},

			// 隐藏弹窗
			cancelConfirm() {
				const _this = this
				_this.showCancelPop = true;
			},

			// 取消支付
			cancelPay() {
				const _this = this
				clearInterval(_this.interVal);
				_this.showCancelPop = false;
				_this.showPwdPop = false;
				this.$emit('paypopb', false); //更新父组件弹窗的弹出状态
				_this.interVal = null
				_this.onChosePay = 'balance';
				//发布任务放弃支付跳转到任务列表
				if (_this.payInfo.subject == '发布任务') {
					uni.navigateBack({
						delta: 2,
						success: res => {
							uni.redirectTo({
								url: app.globalData.platForm == 'web' ? '/taskmanage?index=0' :
									'/pages/packages/task/taskmanage/taskmanage?index=0'
							});
						}
					});
				}
			},

			keepPay() {
				const _this = this
				_this.showCancelPop = false
			},

			toPay() {
				const _this = this
				if (_this.onChosePay == 'balance') {
					_this.showPwdPop = true;
					_this.keyboardShow = true;
					_this.hasshowPwdPop = true
				} else {
					// 直接支付
					console.log('开始支付');
					_this.checkPwd();
				}
			},

			// 关闭弹窗
			hidePwdPop() {
				const _this = this
				_this.showPwdPop = false;
				_this.keyboardShow = false;
				_this.hasshowPwdPop = false;
				_this.paypwd = [];
				_this.paypwdStr = ''
			},

			// 聚焦input
			focusin() {
				const _this = this
				_this.hasshowPwdPop = true;
				if(_this.uniplatform != 'web'){ //web端需要显示密码键盘
					_this.focus = true
				}else{
					_this.keyboardShow = true
				}
			},

			showKeyboard(e) {
				const _this = this
				if (e.detail.height && _this.keyboardHeight != e.detail.height) {
					_this.keyboardHeight = e.detail.height
				}
				if (_this.showPwdPop && e.detail.height) {
					_this.hasshowPwdPop = true;

					if(_this.uniplatform != 'web'){
						_this.focus = true
					}else{
						_this.focus = false; //h5端不自动聚焦
						_this.keyboardShow = true;
					}

				}
			},

			// 跳转页面
			goLink(e) {

				var memberUrl = app.globalData.appConfig.cfg_user_index;
				var url = memberUrl + e.currentTarget.dataset.href;
				app.linkTo(url)
				// uni.navigateTo({
				// 	url: '/pages/redirect/index?url=' + encodeURIComponent(app.encodeUrl(url))
				// });
			},

			// 输入密码
			inputPwd(e) {
				const _this = this
				// if(e.detail.keyCode)
				var pwd = e.detail.value;
				var pwdArr = pwd.split('');
				if (pwdArr.length > 6 && e.detail.keyCode != 8) {
					return false;
				}
				_this.paypwd = pwd.split('')
				if (pwdArr.length == 6) {
					_this.checkPwd();
				}
			},

			keyBoardIn(val){
				const _this = this
				if(_this.paypwd.length >= 6) return;
				_this.paypwd.push(val);
				if(_this.paypwd.length == 6){
					_this.checkPwd();
				}
			},

			// 验证支付密码/支付
			checkPwd(direct) {
				const _this = this
				if (_this.checkIn || (_this.userInfo.paypwdCheck != 1 && !direct && _this.onChosePay == 'balance')) {
					return false;
				}
				_this.checkIn = true;
				// 数据整理
				let data = {
					service: _this.service,
					action: _this.action,
					ordernum: _this.payInfo.ordernum,
					paytype: _this.action == 'pay' && _this.onChosePay == 'balance' ? 'money' : _this.onChosePay
				};
				if (_this.onChosePay == 'balance' ) {
					data['useBalance'] = 1;
					data['paypwd'] = _this.paypwd.join('');
					data['balance'] = _this.payInfo.order_amount;
				} else {
					data['useBalance'] = 0;
				}
				if(!direct){
					data['final'] = 1;
				}
				let platForm = app.globalData.platForm;
				if (platForm == 'mp-toutiao') { //抖音平台支付
					if (_this.onChosePay == 'bytemini') { // 抖音原生支付
						let str = '';
						for (let key in data) {
							str += `&${key}=${data[key]}`;
						};
						let url = `${app.globalData.masterDomain}/include/ajax.php?${str}`
						uni.navigateTo({
							url: '/pages/redirect/index?url=' + encodeURIComponent(url)
						})
					} else { //其他支付方式
						_this.payRequest(data, function(res) {
							//可以直接查看支付状态
							_this.paySuccess();
							_this.paypwd = [];
							_this.paypwdStr = ''
						});
					}
				} else if (platForm == 'mp-weixin') { //微信支付
					if (_this.onChosePay == 'wxpay') { //微信原生支付
						_this.payRequest(data, function(res) {
							_this.payBywxChat(res.data.info);
						})
					} else { //其他支付方式
						_this.payRequest(data, function(res) {
							_this.paySuccess();
							_this.paypwd = [];
							_this.paypwdStr = ''
						})
					}
				} else if (platForm == 'web') { //H5、APP支付
					if (window.appBoolean && (_this.onChosePay == 'wxpay' || _this.onChosePay == 'alipay')) { //App支付
						_this.$ajax.post({
							url: app.encodeUrl('include/ajax.php?mark=pay&app=1'),
							data: data
						}).then(res => {
							if (res.data.state == 100) {
								console.log(11111 )
								window.setupWebViewJavascriptBridge(function(bridge) {
									bridge.callHandler(_this.onChosePay == 'wxpay' ? 'wechatPay' :
										'aliPay', {
											"orderInfo": res.data.info
										},
										function(responseData) {});
								});
							}
						})
					} else if (_this.onChosePay == 'wxpay' || _this.onChosePay == 'alipay') { //H5的微信和支付宝支付
						let str = '';
						for (let key in data) {
							str += `&${key}=${data[key]}`;
						};
						str = str.slice(1);
						location.href = `${app.globalData.masterDomain}/include/ajax.php?${str}`;
					} else { // H5的其他方式支付
						_this.payRequest(data,function(res){
							//可以直接查看支付状态
							_this.paySuccess();
							_this.paypwd = [];
							_this.paypwdStr = ''
						})
					}
				}
			},
			payRequest(data, fn) { //支付请求
				const _this = this
				uni.showLoading({
					title: '支付中...'
				});
				// 微信原生、所有平台余额、所有平台购物卡
				_this.$ajax.post({
					url: app.encodeUrl('include/ajax.php?mark=pay'),
					data: data
				}).then(res => {
					// console.log('其他支付方式')
					uni.hideLoading();
					_this.checkIn = false
					if (res.data.state && res.data.state != 100) {
						_this.$refs.toasts.showToast(res.data.info);
						_this.paypwd = [];
						_this.paypwdStr = '';
					} else if (res.data.state == 100) {
						fn(res);
					} else {
						_this.paypwd = [];
						_this.paypwdStr = ''
						_this.$refs.toasts.showToast('网络请求失败，请稍后重新请求，错误代码：' + JSON.stringify(res.data));
					}
				})
			},
			// 微信支付
			payBywxChat(data) {
				const _this = this
				console.log(data)
				//调起微信支付
				uni.requestPayment({
					//相关支付参数
					timeStamp: data.timeStamp,
					nonceStr: data.nonceStr,
					package: data.package,
					signType: data.signType,
					paySign: decodeURIComponent(data.paySign),
					//小程序微信支付成功的回调通知
					success: function(res) {
						_this.paySuccess(); //支付成功
					},

					//小程序支付失败的回调通知
					fail: function(res) {
						console.log(res);
						_this.$refs.toasts.showToast('支付失败！');
					}
				});
			},
			//抖音支付
			paybytoutiao(data) {
				const _this = this
				console.log(data);
				return
				uni.requestPayment({
					orderInfo: '',
					service: 5,
					//相关支付参数
					//小程序微信支付成功的回调通知
					success: function(res) {
						_this.paySuccess(); //支付成功
					},
					//小程序支付失败的回调通知
					fail: function(res) {
						console.log(res);
						_this.$refs.toasts.showToast('支付失败！');
					}
				});
			},

			// // 查看是否支付成功
			
			// 初始化数据
			initData(data) {
				const _this = this
				_this.$emit('keepToCall', {
					detail: data,
				}); //触发父组件方法
				_this.$emit('paypopb', false); //更新父组件弹窗的弹出状态
				_this.paypwd = [];
				_this.onChosePay = 'balance';
				_this.money = 0;
				//余额
				_this.bouns = 0;
				//购物卡余额,
				_this.showPwdPop = false;
				//支付密码弹窗显示
				_this.showCancelPop = false;
				//取消支付弹窗显示
				_this.hasshowPwdPop = false
				_this.getMemberInfo();
			},

			// 支付成功之后执行的操作
			paySuccess() {
				// wx.showToast({
				//   title: '支付成功！',
				//   icon: 'success',
				//   duration: 2000
				// })
				const _this = this
				clearInterval(_this.interVal);
				if (_this.needSuccess) {
					var successIcon = _this.imgPath + '/payPop/successIcon.png?v=' + _this.imgVersion;
					_this.$refs.toasts.showToast('支付成功', successIcon);
				}
				_this.getPhoneInfo();
			},

			// 验证是否支付成功
			getPhoneInfo() {
				const _this = this
				var dataPrarm = 'service=member&action=tradePayResult&order=' + _this.payInfo.ordernum;
				var urlData = dataPrarm;
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					if (data.state == 100) {
						_this.initData(data);
					}
				})
			},

			  // 设置支付密码
			 setPayPwd: function () {
				const _this = this
                var that = this;
                if (that.loading) return false;
                if (that.paypwd.length != 6) {
                    showErrAlert('请输入新密码');
                    return false;
                }
                that.loading = true;
                let param = "&pay1=" + that.paypwd.join('') + "&pay2=" + that.paypwd.join('');
				var dataPrarm = 'service=member&action=updateAccount&do=paypwdAdd' + param;
				var urlData = app.encodeUrl(dataPrarm)
				that.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					that.loading = false;
					if (data.state == 100) {
						var successIcon = _this.imgPath + '/payPop/successIcon.png?v=' + _this.imgVersion;
						that.$refs.toasts.showToast('支付密码设置成功', successIcon);
						that.checkPwd(1); //重新验证
					}
				})
            },

			// 计算倒计时时间
			payCutDown(payInfo, endTime,offTime = 0) {
				const _this = this
				// endTime = Number(endTime)  + Number(offTime) - .3;
				// 设置倒计时是30分钟
				endTime = parseInt(new Date().valueOf() / 1000) +  1800
				if (payInfo.order_amount > _this.money) {
					_this.onChosePay = _this.payment[0].pay_code
				}
				if (_this.interVal) {
					clearInterval(_this.interVal);
				}
				_this.timeInfo = {
						dd: '0',
						hh: '00',
						mm: '00',
						ss: '00',
						showText: '0天0小时0分钟0秒'
					};
				_this.interVal = setInterval(function() {
					var timestamp = parseInt(Date.parse(new Date()));
					if (endTime * 1000 - timestamp > 0) {
						var timeOff = endTime * 1000 - timestamp;
					} else {
						var timeOff = 0;
					}
					if (!timeOff) {
						clearInterval(_this.interVal);
					}
					var leftd = Math.floor(timeOff / (3600000 * 24));
					var //计算天数
						lefth = Math.floor((timeOff / 3600000) % 24);
					var //计算小时数
						leftm = Math.floor((timeOff / 60000) % 60);
					var //计算分钟数
						lefts = Math.floor((timeOff / 1000) % 60); //计算秒数
					var timeInfo = {
						dd: leftd > 9 ? leftd : '0' + leftd,
						hh: lefth > 9 ? lefth : '0' + lefth,
						mm: leftm > 9 ? leftm : '0' + leftm,
						ss: lefts > 9 ? lefts : '0' + lefts,
						showText: leftd ? leftd + '天' : lefth ? lefth + '小时' : leftm ? leftm + '分钟' : lefts +
							'秒'
					};
					_this.timeInfo = timeInfo
				}, 1000);
			},

			showtoast() {
				// var successIcon = that.data.imgPath + '/payPop/successIcon.png?v=' + that.data.imgVersion
				// that.toast.showToast('恭喜你，获得了toast',successIcon);
				console.log('测试方法');
			},

			trueFun() {
				console.log('占位：函数 true 未声明');
			}
		},
		created() {
			const _this = this;
			_this.getPayment();
			if (app.globalData.userid) {
				_this.getMemberInfo();
			}
			setTimeout(res => {
				_this.timeoutpay = false;
			}, 400)
		},
		mounted() {
			const _this = this;
			this.uniPlatform = uni.getSystemInfoSync().uniPlatform;
			if(this.uniPlatform == 'web'){
				this.focus = false; //如果当前终端是h5 则不调用原生输入框 
				this.hasshowPwdPop = false;
			}

			if (JSON.stringify(app.globalData.userInfo) != '{}') {
				this.userInfo = app.globalData.userInfo;
			} else {
				uni.getStorage({
					key: 'userid',
					success: res => {
						app.memberInfo(res.data, function(info) {
							_this.userInfo = info;
						});
					},
				})
			}
			// 处理小程序 ready 生命周期
			this.$nextTick(() => this.ready());

			
		},
		unmounted(){
			const _this = this
			clearInterval(_this.interVal);
		},
		watch:{
			showPayPop(newVal,oldVal){
				if(newVal&&app.globalData.iOSMiniPay_forbid){
					uni.showModal({
						title: '温馨提示',
						content: app.globalData.iosMiniPay_msg||'十分抱歉，由于相关规范，iOS小程序不支持该功能。',
						showCancel: false, //隐藏取消按钮
						success:res=>{
							if(res.confirm){
								this.$emit('paypopb', false);
							}
						}
					});
					return false
				}

				// 只使用第三方支付
				if(newVal && this.filterPay && this.onChosePay == 'balance'){
					this.onChosePay = this.payment[0].pay_code
				}
			}
		}
	};
</script>
<style>
	@import './public_pay.css';
</style>